import { Component, Vue, Inject } from 'vue-property-decorator';

import { IRoomListingFeature } from '@/shared/model/room-listing-feature.model';
import RoomListingFeatureService from './room-listing-feature.service';
import AlertService from '@/shared/alert/alert.service';

@Component
export default class RoomListingFeatureDetails extends Vue {
  @Inject('roomListingFeatureService') private roomListingFeatureService: () => RoomListingFeatureService;
  @Inject('alertService') private alertService: () => AlertService;

  public roomListingFeature: IRoomListingFeature = {};

  beforeRouteEnter(to, from, next) {
    next(vm => {
      if (to.params.roomListingFeatureId) {
        vm.retrieveRoomListingFeature(to.params.roomListingFeatureId);
      }
    });
  }

  public retrieveRoomListingFeature(roomListingFeatureId) {
    this.roomListingFeatureService()
      .find(roomListingFeatureId)
      .then(res => {
        this.roomListingFeature = res;
      })
      .catch(error => {
        this.alertService().showHttpError(this, error.response);
      });
  }

  public previousState() {
    this.$router.go(-1);
  }
}
